package online.flowerinsnow.minecraft.bukkit.manhunt.session.msic;

import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask;
import online.flowerinsnow.minecraft.bukkit.manhunt.Manhunt;

public class TaskSession {
    public int delay;
    public int period;

    public TaskSession() {
        this(0, 0);
    }

    public TaskSession(int delay, int period) {
        this.delay = delay;
        this.period = period;
    }

    public BukkitTask sync(Runnable runnable) {
        return Manhunt.runTask(runnable);
    }

    public BukkitTask syncSchedule(Runnable runnable, int delay) {
        return Bukkit.getScheduler().runTaskLater(Manhunt.getInstance(), runnable, delay);
    }

    public BukkitTask syncSchedule(Runnable runnable) {
        return this.syncSchedule(runnable, this.delay);
    }

    public BukkitTask syncRepeat(Runnable runnable, int delay, int period) {
        return Bukkit.getScheduler().runTaskTimer(Manhunt.getInstance(), runnable, delay, period);
    }

    public BukkitTask syncRepeat(Runnable runnable) {
        return this.syncRepeat(runnable, this.delay, this.period);
    }

    public BukkitTask async(Runnable runnable) {
        return Bukkit.getScheduler().runTaskAsynchronously(Manhunt.getInstance(), runnable);
    }

    public BukkitTask asyncSchedule(Runnable runnable, int delay) {
        return Bukkit.getScheduler().runTaskLaterAsynchronously(Manhunt.getInstance(), runnable, delay);
    }

    public BukkitTask asyncSchedule(Runnable runnable) {
        return this.syncSchedule(runnable, this.delay);
    }

    public BukkitTask asyncRepeat(Runnable runnable, int delay, int period) {
        return Bukkit.getScheduler().runTaskTimerAsynchronously(Manhunt.getInstance(), runnable, delay, period);
    }

    public BukkitTask asyncRepeat(Runnable runnable) {
        return this.syncRepeat(runnable, this.delay, this.period);
    }

    public TaskSession setDelay(int delay) {
        this.delay = delay;
        return this;
    }

    public TaskSession setPeriod(int period) {
        this.period = period;
        return this;
    }

    public TaskSession setTime(int delay, int period) {
        this.delay = delay;
        this.period = period;
        return this;
    }
}
